﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using NLBS.Entity;
using System.Data;
using NHibernate.Criterion;

namespace NLBS.Data
{
    public partial class NHibernateDataProvider : DbProvider
    {
        public override IList<ExtensionLink> GetExtensionLink(int Type)
        {
            IList<ExtensionLink> list = CurrentSession.CreateCriteria(typeof(ExtensionLink))
                  .Add(Expression.Eq("Type", Type))
                  .AddOrder(Order.Asc("OrderId")).List<ExtensionLink>();

           
            return list;
        }

        public override IList<ExtensionLink> GetExtensionLink()
        {
            return CurrentSession.CreateQuery("select e from ExtensionLink as e").List<ExtensionLink>();
        }

        public override int InsertExtensionLink(ExtensionLink link)
        {
            CurrentSession.Save(link);
            return 1;
        }

        public override int UpdateExtensionLink(ExtensionLink link)
        {
            CurrentSession.Update(link);
            CurrentSession.Flush();
            return 1;
        }

        public override int DeleteExtensionLink(int id)
        {
            CurrentSession.Delete(GetExtensionLinkDetail(id));
            CurrentSession.Flush();
            return 1;
        }

        public override ExtensionLink GetExtensionLinkDetail(int id)
        {
            return CurrentSession.Get<ExtensionLink>(id);
           
            
        }
    }
}
